<%--
  Created by IntelliJ IDEA.
  User: RE1UY
  Date: 2021/10/10
  Time: 11:02
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
    <title>已经上传的商品</title>

    <script src="/reiCode/js/jquery-3.5.1.js" type="text/javascript"></script>
    <!--可能是失败的尝试 能实现功能,但不够优,且在开发对商品的操作功能时会出现问题
    <script>
        window.onload=function () {
            var str = ''
            var obj = eval(str);
            //将goodlist进行序列化之后遍历
            for(var i=0;i<obj.length; i++){
                document.getElementById(i).innerHTML=
                    "<td>"+obj[i].goodid+"</td>"+
                    "<td>"+obj[i].goodname+"</td>"+
                    "<td>"+obj[i].goodprice+"</td>"+
                    "<td>"+obj[i].goodintro+"</td>"+
                    "<td>"+obj[i].goodtag+"</td>"

            }
        }
        function deletegood() {
            var data = "goodid="
            $.ajax({
                url:
                type:"get",
                dataType:"text",
                data: data,
                success:function (data) {
                    alert("删除成功")
                }
            })
        }

    </script>
    -->
    <script>
        function deletegood(goodid) {
            if(confirm("您确定要删除这个商品吗")){
                $.ajax({
                    url:"${pageContext.request.contextPath}/good/deletegood.do",
                    type:"get",
                    dataType:"text",
                    data:{"goodid":goodid},
                    success:function (msg) {
                        alert(msg);
                        location.reload();
                    }

                })
            }
        }
    </script>

</head>
<body>
<center>
    <table border="1">
        <tr>
            <th>商品id</th>
            <th>商品名称</th>
            <th>商品价格</th>
            <th>商品介绍</th>
            <th>商品分类</th>
            <th>操作</th>
        </tr>
        <c:forEach items="${usergoods}" var="g">
            <tr>
            <td>${g.goodid}</td>
            <td>${g.goodname}</td>
            <td>${g.goodprice}</td>
            <td>${g.goodintro}</td>
            <td>${g.goodtag}</td>
            <td><input type="button" value="删除" onclick="deletegood(${g.goodid})"></td>
            </tr>
        </c:forEach>
    </table>
</center>
</body>
</html>

